﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace 文件浏览
{
    public partial class uploadfile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string uploadtime = DateTime.Now.ToString();

            if(FileUpload1.HasFile == false)
            {
                ClientScript.RegisterClientScriptBlock(typeof(Page),"","window.alert('请先选择要上传的文件! ');",true);
                return;
            }

            var type = FileUpload1.PostedFile.ContentType;
            if(type != "application/msword" 
                &&  type != "application/pdf"
                &&  type != "image/pjpeg"
                &&  type != "image/bmp"
                &&  type != "audio/mp3"
                )
            {
                ClientScript.RegisterClientScriptBlock(typeof(Page), "", "window.alert('您只能上传一下格式的文件:DOC/PDF/pjpeg/BMP/MP3 ');", true);
                ClientScript.RegisterClientScriptBlock(typeof(Page), "", "window.alert('您只能上传的格式为:"+type+"');", true);

            }

            try
            {
                Labelfilename.Text = FileUpload1.FileName;
                LabelfileSize.Text = FileUpload1.PostedFile.ContentLength / 1024 + "kb";
                Labelfiletype.Text = FileUpload1.PostedFile.ContentType;
                Labelsource.Text = "用户上传";
                Labeluploadtime.Text = uploadtime;
            }
            catch (Exception err)
            {

            }


        }
    }
}